<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../static/sass/index.css">
</head>

<body>
    <div class="home-container">
        <div class="admin-container">
            <div class="admin-title">
                {{Title}}
            </div>
            <div class="admin-content">
                <div class="input-wrapper">
                    <label for="name">Username:</label>
                    <input type="text" id="name">
                    <button class="clear-btn" onclick="clearInput('name')">&times;</button>
                </div>
                <br>
                <div class="input-wrapper">
                    <label for="password">Password:</label>
                    <input type="text" id="password">
                    <button class="clear-btn" onclick="clearInput('password')">&times;</button>
                </div>
                <div class="input-wrapper">
                    <label for="rememberMe" class="checkbox-label">
                        记住密码
                    </label>
                    <div class="checkbox-wrapper">
                        <input type="checkbox" id="rememberMe">
                        <div class="checkbox-custom"></div>
                    </div>
                </div>
                <div class="admin-btn" id="submit">登录</div>
            </div>
        </div>
    </div>
    <script src="../static/js/common.js"></script>
</body>
<script>
    let title = "{{Title}}";
    //从后端接收json数据
    let names = JSON.parse('{{names|safe}}');
    (async () => {
        let username = document.querySelector('#name')
        let password = document.querySelector('#password')
        document.querySelector('#submit').addEventListener('click', async () => {
            let data = await ajax.post("/admin/login", { name: username.value, password: password.value })
            if (data.code === 0) {
                modal(`${username.value}登录成功`)
                // 跳转到首页
                setTimeout(() => {
                    window.location.href = '/home'
                }, 1000)
            } else {
                modal(`${username.value}登录失败,请联系管理员处理`)
            }
        })
    })()
</script>

</html>